package net.csdn.business.kanban.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import net.csdn.business.kanban.api.facade.KanbanDetailFacade;
import net.csdn.business.kanban.api.service.KanbanDetailService;
import net.csdn.business.kanban.common.domain.request.IssueLinkKanbanUpdateParam;
import net.csdn.business.kanban.common.domain.request.KanbanDetailAddParam;
import net.csdn.business.kanban.common.domain.request.KanbanDetailUpdateParam;
import net.csdn.business.kanban.common.domain.request.MoveIssueParam;
import net.csdn.business.kanban.common.domain.resp.IssueInfoResp;
import net.csdn.business.kanban.common.domain.resp.KanbanDetailResp;
import net.csdn.business.kanban.feign.annotation.Inner;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import java.util.*;
/**
 * @ClassName KanbanDetailController
 * @Description TODO
 * @Author liuzhisheng
 * @Date 2023/9/14
 **/
@Inner
@RestController
@RequestMapping("/api/v1/kanban/detail")
@RequiredArgsConstructor
@Api(tags = "看板明细内容")
public class KanbanDetailController {
    private final KanbanDetailService kanbanDetailService;
    private final KanbanDetailFacade kanbanDetailFacade;

    @GetMapping
    @ApiOperation(value = "issue详情接口")
    public IssueInfoResp getKanbanDetailById(@RequestParam("id") String objectId,@RequestParam("uid") String uid) {
        return kanbanDetailFacade.getKanbanDetailById(objectId,uid);
    }

    @GetMapping("/issue/url")
    @ApiOperation(value = "issue跳转链接")
    public String getIssueUrl(@RequestParam("id") String objectId) {
        return kanbanDetailFacade.getIssueUrl(objectId);
    }

    @PostMapping
    @ApiOperation(value = "添加任务")
    public boolean addKanbanDetail(@Validated @RequestBody KanbanDetailAddParam param){
        return kanbanDetailFacade.addKanbanDetail(param);
    }

    @PutMapping
    @ApiOperation(value = "内容编辑接口")
    public boolean updateKanbanDetail(@Validated @RequestBody KanbanDetailUpdateParam param) {
        return kanbanDetailFacade.updateKanbanDetail(param);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "从看板中移除任务")
    public boolean deleteKanbanDetail(@PathVariable("id") String id) {
        return kanbanDetailService.deleteKanbanDetail(id);
    }

    @GetMapping("/list/{kanbanId}")
    @ApiOperation(value = "看板任务列表")
    public List<KanbanDetailResp> kanbanDetailsList(@PathVariable("kanbanId") String kanbanId,
                                                    @RequestParam(value = "archivedTask",required = false) Boolean archivedTask) {
        return kanbanDetailFacade.kanbanDetailsList(kanbanId,archivedTask);
    }

    @PutMapping("/{id}/archived")
    @ApiOperation(value = "任务归档/还原")
    public boolean archived(@PathVariable("id") String id,@RequestParam(value = "archivedTask") Boolean archivedTask) {
        return kanbanDetailService.archived(id,archivedTask);
    }


    @PutMapping("/issueUpdateSync")
    @ApiOperation(value = "issue变更同步kanban")
    public void issueUpdateSync(@Validated @RequestBody IssueLinkKanbanUpdateParam param) {
        kanbanDetailFacade.issueLinkUpdate(param);
    }

    @DeleteMapping("/removeByIssueId/{issueId}")
    @ApiOperation(value = "根据issueId移出看板")
    public boolean removeByIssueId(@PathVariable("issueId") String issueId) {
        kanbanDetailFacade.removeIssue(issueId);
        return true;
    }

    @PutMapping("/moveIssue")
    @ApiOperation(value = "转移issue同步更新看板issue")
    public boolean moveIssue(@Validated @RequestBody MoveIssueParam param) {
        kanbanDetailFacade.moveIssue(param);
        return true;
    }

}

